using Hospital.API.Dto;
using Hospital.API.HospitalServices.IServices;
using Hospital.Domain;
using Hospital.ErrorCode;
using Microsoft.AspNetCore.Mvc;

namespace Hospital.API.Controllers
{
    /// <summary>
    /// 工作流管理控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller][action]")]
    public class WorkflowController : ControllerBase
    {
        private readonly IWorkflowServices _workflowServices;
        private readonly ILogger<WorkflowController> _logger;

        public WorkflowController(
            IWorkflowServices workflowServices,
            ILogger<WorkflowController> logger)
        {
            _workflowServices = workflowServices;
            _logger = logger;
        }

        /// <summary>
        /// 创建工作流
        /// </summary>
        /// <param name="createWorkflowDto">创建工作流请求</param>
        /// <returns>工作流信息</returns>
        [HttpPost]
        public async Task<APIResult<WorkflowDto>> CreateWorkflow([FromBody] CreateWorkflowDto createWorkflowDto)
        {
            return await _workflowServices.CreateWorkflow(createWorkflowDto);
        }

        /// <summary>
        /// 获取工作流列表
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <returns>工作流列表</returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<List<WorkflowDto>>>> GetWorkflowList([FromQuery] WorkflowQueryDto queryDto)
        {
            return await _workflowServices.GetWorkflowList(queryDto);
        }

        /// <summary>
        /// 根据ID获取工作流详情
        /// </summary>
        /// <param name="id">工作流ID</param>
        /// <returns>工作流详情</returns>
        [HttpGet]
        public async Task<APIResult<WorkflowDto>> GetWorkflowById(int id)
        {
            return await _workflowServices.GetWorkflowById(id);
        }

        /// <summary>
        /// 更新工作流步骤
        /// </summary>
        /// <param name="updateStepDto">更新步骤请求</param>
        /// <returns>更新结果</returns>
        [HttpPut]
        public async Task<APIResult<bool>> UpdateWorkflowStep([FromBody] UpdateWorkflowStepDto updateStepDto)
        {
            return await _workflowServices.UpdateWorkflowStep(updateStepDto);
        }

        /// <summary>
        /// 获取服务类型列表
        /// </summary>
        /// <returns>服务类型列表</returns>
        [HttpGet]
        public async Task<APIResult<List<ServiceType>>> GetServiceTypes()
        {
            return await _workflowServices.GetServiceTypes();
        }
    }
} 